from libs.ZButton import ZButton
from libs.ZImage import ZImage
from libs.ZScene import ZScene
from libs.ZText import ZText
from libs.fun import play_music
from project.res.glo import glo
from project.res.lang import lang_cn
from project.res.src import src
from libs.components.ZMessage import ZMessage


class MainScene ( ZScene ) :
    def __init__ ( self ) :
        super ( MainScene , self ).__init__ ( )
        self.playmusic ( )
        self.background ( )
        self.msg_layer ( )
        self.button ( )

    def playmusic ( self ) :
        play_music ( src.music.mainscene [ 'bgm' ] )

    def background ( self ) :
        self.add ( ZImage ( self , src.image.mainscene [ "test_jpg" ] ) )

    def button ( self ) :
        self.add ( StartBtn ( self ) )
        self.add ( ExitBtn ( self ) )


class ExitBtn ( ZButton ) :
    def __init__ ( self , father ) :
        text1 = ZText ( self , src.font.default , lang_cn.button [ 'exit' ] , glo.font [ 1 ] , glo.color [ 0 ] )
        text2 = ZText ( self , src.font.default , lang_cn.button [ 'exit' ] , glo.font [ 1 ] , glo.color [ 1 ] )
        super ( ExitBtn , self ).__init__ ( father , text1.image , text2.image )
        self.center ( )
        self._pos = self._pos [ 0 ] , self._pos [ 1 ] + 30

    def action ( self ) :
        exit ( )


class StartBtn ( ZButton ) :
    def __init__ ( self , father ) :
        text1 = ZText ( self , src.font.default , lang_cn.button [ 'start' ] , glo.font [ 1 ] , glo.color [ 0 ] )
        text2 = ZText ( self , src.font.default , lang_cn.button [ 'start' ] , glo.font [ 1 ] , glo.color [ 1 ] )
        super ( StartBtn , self ).__init__ ( father , text1.image , text2.image )
        self.center ( )
        self.i = 0

    def action ( self ) :
        from libs.ZDirector import ZDirector
        from project.scenes.PlayerSelectScene.PlayerSelectScene import PlayerSelectScene
        ZDirector ( ).show ( PlayerSelectScene ( ) )
        # self.father.add ( ZMoveTo ( self.father.children [ 0 ] , [ 10 , 600 ] ) )
        # self.i += 1
        # text = ZText ( self.father.msg_info , src.font.default , str ( self.i ) , glo.font [ 1 ] , glo.color [ 0 ] )
        # self.father.msg_info.add ( text )
